<?php

namespace app\common\model;

use think\Model;

class Behavior extends Model
{
    // 表名
    protected $name = 'behavior';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    // 定义时间戳字段名
    protected $createTime = 'created_at';
    protected $updateTime = false;

    //protected $append = ['status_text', 'type_text', 'category_text'];

    const POSITIVE = 1; //积极的
    const NEGATIVE = 2; //消极的

    const ABNORMAL = 0;
    const NORMAL = 1;

    public static $statusList = [
        '0' => '未启用',
        '1' => '启用',
    ];

    public static $typeList = [
        '1' => '积极的',
        '2' => '消极的',
    ];

    const DORM = 1;
    const STUDENT = 2;

    public static $categoryList = [
        '1' => '宿舍',
        '2' => '学生',
    ];

    /*public function category()
    {
        return $this->belongsTo('BehaviorCategory', 'category_id', 'id', [], 'left');
    }

    public function image()
    {
        return $this->belongsTo('BehaviorImage', 'image_id', 'id', [], 'left');
    }*/

    public function getStatusTextAttr($value, $data)
    {
        return isset(self::$statusList[$data['status']]) ? self::$statusList[$data['status']] : '';
    }

    public function getTypeTextAttr($value, $data)
    {
        return isset(self::$typeList[$data['type']]) ? self::$typeList[$data['type']] : '';
    }

    public function getCategoryTextAttr($value, $data)
    {
        return isset(self::$categoryList[$data['category_id']]) ? self::$categoryList[$data['category_id']] : '';
    }
}
